using System.Collections;
using UnityEngine;
namespace cframework.lockstep
{
    public static class CoroutineWithResult
    {
        public static IEnumerator WithResult(this IEnumerator co)
        {
            bool first = true;
            while (co.Current == null || co.Current is IEnumerator || co.Current is YieldInstruction)
            {
                if (!first) //第一次要先运行MoveNext
                {
                    yield return co.Current;
                }

                first = false;

                if (!co.MoveNext()) //返回false代码运行结束无返回值
                {
                    yield break;
                }
            }

            yield return co.Current; //把co的返回值给协程容器,让外层代码可以访问到
        }
    }
}